package net.stogi.common.api.dto;

import java.io.Serializable;

/**
 * Order class marker created for use in all layers.
 */
public class OrderBy implements Serializable {

	private static final long serialVersionUID = -3004732939768257806L;

	/**
	 * Ascending order.
	 * 
	 * @param propertyName
	 *            property name to order
	 * @return {@link OrderBy} instance
	 */
	public static OrderBy asc(String propertyName) {
		return new OrderBy(propertyName, true);
	}

	/**
	 * Descending order.
	 * 
	 * @param propertyName
	 *            property name to order
	 * @return {@link OrderBy} instance
	 */
	public static OrderBy desc(String propertyName) {
		return new OrderBy(propertyName, false);
	}

	/**
	 * Order flag.
	 */
	private boolean ascending;

	/**
	 * Property name to order by.
	 */
	private String propertyName;

	protected OrderBy() {}

	/**
	 * Constructor for Order.
	 */
	protected OrderBy(String propertyName, boolean ascending) {
		this.propertyName = propertyName;
		this.ascending = ascending;
	}

	/**
	 * @return the orderBy
	 */
	public String getPropertyName() {
		return propertyName;
	}

	/**
	 * @return the ascending
	 */
	public boolean isAscending() {
		return ascending;
	}

	@Override
	public String toString() {
		return propertyName + " " + (ascending ? "asc" : "desc");
	}
}
